#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
struct rec
{
	int x, y, h;
	bool friend operator < (rec a,rec b)
	{
		if(a.x==b.x)return a.y>b.y;
		return a.x>b.x;
	}
}r[91];
int n;
long long dp[91];
void swap(int &x,int &y)
{
	int t;
	t=x;
	x=y;
	y=t;
}
int max(int x,int y)
{
	return x>y?x:y;
}
int main()
{
	int cnt=0;
	while(scanf("%d",&n)&&n)
	{
		cnt++;
		int m=0;
		for(int i=1;i<=n;i++)
		{
			int x,y,z;
			scanf("%d%d%d",&x,&y,&z);
			m++;
			if(x>y)swap(x,y);
			if(x>z)swap(x,z);
			if(y>z)swap(z,y);
			r[m].x=x;r[m].y=y;r[m].h=z;
			if(x==y&&y!=z)
			{
				m++;
				r[m].x=x;r[m].y=z;r[m].h=y;

			}
			if(x!=y&&y==z)
			{
				m++;
				r[m].x=y;r[m].y=y;r[m].h=x;
			}
			if(x!=y&&y!=z)
			{
				m++;r[m].x=y;r[m].y=z;r[m].h=x;
				m++;r[m].x=x;r[m].y=z;r[m].h=y;
			}
		}
		sort(r+1,r+m+1);
		dp[1]=r[1].h;
		long long ans=dp[1];
		for(int i=2;i<=m;i++)
		{
			dp[i]=r[i].h;
			for(int j=i-1;j>=1;j--)
				if(r[j].x>r[i].x&&r[j].y>r[i].y)dp[i]=max(dp[i],dp[j]+r[i].h);
			ans=max(ans,dp[i]);
		}
		cout<<"Case "<<cnt<<": maximum height = "<<ans<<endl;
	}
	return 0;
}

